<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%--企业续签页面--%>
<form id="mySubordinateForm">
    <div class="body-main">
        <input type="hidden" id="scOrderId" value="0">

        <div id="proAttached">
            <table class="add-table form-table">
                <tbody>
                <tr>
                    <th><span class="required">证书使用的企业订单：</span></th>
                    <td>
                        <input type="text" style="width: auto" class="input-style" maxlength="100" name="scOrderNo" id="scOrderNo" placeholder="生产订单编号">
                        <button type="button" class="layui-btn layui-btn-mini" onclick="checkOrder()" maxlength="100">验证</button>
                    </td>
                </tr>
                <tr>
                    <th><span class="required">使用公司：</span></th>
                    <td>
                        <input type="text" class="input-style" maxlength="200" name="affiliatedCompany"
                               id="affiliatedCompany">
                    </td>
                </tr>
                <tr>
                    <th><span class="required">使用金额（元）：</span></th>
                    <td>
                        <input type="text" class="input-style" maxlength="10" name="certificatePrice"
                               id="certificatePrice" onkeyup="restrictInputLength(this,8)">
                    </td>
                </tr>
                <tr>
                    <th><span class="required">使用起始日期：</span></th>
                    <td>
                        <input type="text" class="input-style Wdate" name="affiliatedStartTime" id="affiliatedStartTime"
                               onFocus="var d4312=$dp.$('affiliatedExpireTime'); WdatePicker({onpicked:function(){d4312.focus();},
                                maxDate:'#F{ $dp.$D(\'affiliatedExpireTime\')}', dateFmt:'yyyy-MM-dd'})"
                        >
                    </td>
                </tr>
                <tr>
                    <th><span class="required">使用结束日期：</span></th>
                    <td>
                        <input type="text" class="input-style Wdate" name="affiliatedExpireTime" id="affiliatedExpireTime"
                               onFocus="WdatePicker({minDate:'#F{$dp.$D(\'affiliatedStartTime\')}', dateFmt:'yyyy-MM-dd'})"
                        >
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</form>
<script type="text/javascript">
    //订单是否可使用证书
    var checkStatus = false;

    /**
     * 提交使用证书
     * @param certificateId
     */
    function confirmAffiliated(certificateId) {
        // debugger
        var scOrderNo = $('#scOrderNo').val();
        if (!scOrderNo) {
            DGG.Warning("请输入生产订单编号!");
            return;
        }
        var certificatePrice = $('#certificatePrice').val();
        if (checkIsEmpty(certificatePrice)) {
            DGG.Warning("请输入使用金额!");
            return;
        }
        var affiliatedCompany = $('#affiliatedCompany').val();
        if (checkIsEmpty(affiliatedCompany)) {
            DGG.Warning("请输入使用公司!");
            return;
        }
        var affiliatedStartTime = $('#affiliatedStartTime').val();
        if (checkIsEmpty(affiliatedStartTime)) {
            DGG.Warning("请输入使用起始时间!");
            return;
        }
        var affiliatedExpireTime = $('#affiliatedExpireTime').val();
        if (checkIsEmpty(affiliatedExpireTime)) {
            DGG.Warning("请输入使用结束时间!");
            return;
        }
        var serializeObject = $('#mySubordinateForm').serializeObject();
        serializeObject.certificateId = certificateId;
        //判断订单编号是否存在
        if (!checkStatus) {
            DGG.Warning("请填写正确的生产订单编号!");
            return;
        }
        var scOrderId = $('#scOrderId').val();
        serializeObject.scOrderId = scOrderId;
        DGG.Confire('确认续签吗？', '使用提示', function () {
            DGG.loading();
            $.ajax({
                type: 'POST',
                data: serializeObject,
                url: sysInfo.basePath + '/zs/general_credential/save_business_renewal.do',
                dataType: 'JSON',
                success: function (data) {
                    DGG.loading('close');
                    if (data.code != 0) {
                        DGG.Errors(data.msg);
                    } else {
                        DGG.Succeed("使用成功!");
                        layer.closeAll();
                        $('#myTable').dataTableExtend("reload");
                    }
                },
                error: function () {
                }
            });
        })

    }

    /**
     * 校验订单是否存在
     */
    function checkOrder() {
        var scOrderNo = $('#scOrderNo').val();
        if (!scOrderNo) {
            DGG.Warning("请输入生产订单编号!");
            return;
        }
        DGG.loading();
        $.post(sysInfo.basePath + '/sc/all/getScOrder.do', {scOrderNo: scOrderNo}, function (result) {
            if (result.code == 0) {
                DGG.Succeed('该订单可以使用证书');
                $("#scOrderId").val(result.data[0]);
                checkStatus = true;
            } else {
                DGG.Errors(result.msg);
                $("#scOrderId").val("");
                checkStatus = false;
            }
            DGG.loading('close');
        }, 'json');
    }
</script>

